﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AirlineProject.Models
{
    public class DataModels
    {
        private DataClassesProjectAirlineDataContext dc = new DataClassesProjectAirlineDataContext();
        public bool Addflight( int orgin_id, int destination_id, DateTime departure_date, double flight_price, int seat_num)
        {
            bool kq = true;
            try
            {
                Flight fl = new Flight();
                fl.origin_id = orgin_id;
                fl.destination_id = destination_id;
                fl.departure_date = departure_date;
                fl.flight_price = flight_price;
                fl.seat_num = seat_num;               
                this.dc.Flights.InsertOnSubmit(fl);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;

        }
        public bool addorigin(int origin_id, string place_name, int place_parentid) 
        {
            bool kq = true;
            try
            {
                Orgin to = new Orgin();
                to.orgin_id = origin_id;
                to.place_name = place_name;
                to.place_parentid = place_parentid;
                this.dc.Orgins.InsertOnSubmit(to);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool adddestination(int destination_id,string place_name,int place_parentid)
        {
            bool kq = true;
            try
            {
                Destination from = new Destination();
                from.destination_id = destination_id;
                from.place_name = place_name;
                from.place_parentid = place_parentid;
                this.dc.Destinations.InsertOnSubmit(from);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        } 
        public List<Ticket> Listticket()
        {
            return this.dc.Tickets.ToList();
        }
        public List<Bill>listbill()
        {
            return this.dc.Bills.ToList();
        }
        public List<Orgin> listorigin()
        {
            return this.dc.Orgins.ToList();
        }
        public List<Destination> listdestination()
        {
            return this.dc.Destinations.ToList();
        }
        public List<TypeTicket> ListTypeTicket()
        {
            return this.dc.TypeTickets.ToList();
        }
        public List<formpayment> ListFormpayment()
        {
            return this.dc.formpayments.ToList();
        }
        public bool deleteflight(int id)
        {
            bool kq = true;

            try
            {
                Flight fl = this.dc.Flights.Single(tk => tk.flight_id.Equals(Convert.ToInt32(id)));
                this.dc.Flights.DeleteOnSubmit(fl);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deletebill(string id)
        {
            bool kq = true;

            try
            {
                Bill bill = this.dc.Bills.Single(tk => tk.bill_id.Equals(id));
                this.dc.Bills.DeleteOnSubmit(bill);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deleteticket(string id)
        {
            bool kq = true;

            try
            {
                Ticket tic = this.dc.Tickets.Single(tk => tk.ticket_id.Equals(id));
                this.dc.Tickets.DeleteOnSubmit(tic);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deleteorigin(int id)
        {
            bool kq = true;

            try
            {
                Orgin o = this.dc.Orgins.Single(tk => tk.orgin_id.Equals(Convert.ToInt32(id)));
                this.dc.Orgins.DeleteOnSubmit(o);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deletedestination(int id)
        {
            bool kq = true;

            try
            {
                Destination des = this.dc.Destinations.Single(tk => tk.destination_id.Equals(Convert.ToInt32(id)));
                this.dc.Destinations.DeleteOnSubmit(des);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deletetypeticket(int id)
        {
            bool kq = true;

            try
            {
                TypeTicket tt = this.dc.TypeTickets.Single(tk => tk.type_id.Equals(Convert.ToInt32(id)));
                this.dc.TypeTickets.DeleteOnSubmit(tt);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
        public bool deleteformpayment(int id)
        {
            bool kq = true;

            try
            {
                formpayment fp = this.dc.formpayments.Single(tk => tk.payment_id.Equals(Convert.ToInt32(id)));
                this.dc.formpayments.DeleteOnSubmit(fp);
                this.dc.SubmitChanges();
            }
            catch
            {
                kq = false;
            }
            return kq;
        }
    }
}